package zuoye;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class sort {
	public static void main(String[] args) throws Exception {
		FileInputStream fis=new FileInputStream("sort.txt");
		BufferedReader br=new BufferedReader(new InputStreamReader(fis, "utf-8"));
		String str;
		ArrayList<String> list=new ArrayList<>();
		while((str=br.readLine())!=null){
			list.add(str);
		}
		br.close();
		List<String> collect = list.stream()
				.sorted(Comparator.comparingInt(s->Integer.parseInt(""+s.charAt(0))))
				.collect(Collectors.toList());
		FileOutputStream fos=new FileOutputStream("sort.txt");
		BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos, "utf-8"));
		for (String string : collect) {
			bw.write(string);
			bw.newLine();
			bw.flush();
		}
		bw.close();
	}
}
